//
//  WBMainViewController.swift
//  WeiBo
//
//  Created by liushaohua on 16/10/22.
//  Copyright © 2016年 liushaohua. All rights reserved.
//

import UIKit

class WBMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // 设置自定义的tabbar
        let tabBar = WBTabBar()
        // 通过KVC设置tabbar
        setValue(tabBar, forKey: "tabBar")
        
        tabBar.closure = {
        print("Main点击了加号")
        
        }

        // 创建四个控制器
        addChildViewController(vc: WBHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(vc: WBMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(vc: WBDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(vc: WBProfileViewController(), title: "我", imgName: "tabbar_profile")
   
 
    }

    
    //MARK: 抽取创建控制器的方法
    
    func addChildViewController(vc:UIViewController, title:String, imgName:String){
    
        vc.title = title
        // 设置文字颜色
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.normal)
        
        //设置文字背景图片
        vc.tabBarItem.image = UIImage(named:imgName)
        
        // 让图片原声渲染方式
        
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        let naVC = WBNavigationController(rootViewController: vc)
        
        addChildViewController(naVC)

    }
    
    

}
